package ywh.model
{
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.geom.Rectangle;
	import flash.text.TextField;
	import ywh.event.StreamEvent;
	import ywh.manager.Core;
	import ywh.player.RelayoutSprite;
	import ywh.pool.StreamPool;
	import ywh.stream.MediaStream;
	
	/**
	 * 图片控制区;
	 * @author ywh
	 */
	public class Model2PicsCtrl extends RelayoutSprite
	{
		public var prevPageBtn:MovieClip;
		public var nextPageBtn:MovieClip;
		public var picsListLayout:RelayoutSprite;
		public var numTxt:TextField;
		private var picsStream:MediaStream;
		
		public function Model2PicsCtrl()
		{
		}
		
		internal function startSync():void
		{
			initEvent();
			setRectangle();
			picsStream = StreamPool.getStreamById("picsshow");			
			Core.addEventListener(StreamEvent.STREAM_LIST_CHANGE_ITEM, streamListChangeItem);		
		}
		
		private function streamListChangeItem(e:StreamEvent):void
		{
			if (e.stream == picsStream)
			{
				numTxt.text = (e.stream.currentIndex + 1) + " / " + e.stream.count;
			}
		
		}
		
		private function initEvent():void
		{
			prevPageBtn.buttonMode = true;
			nextPageBtn.buttonMode = true;
			this.addEventListener(MouseEvent.MOUSE_DOWN, this_mouseDown);
		}
		
		private function this_mouseDown(e:MouseEvent):void
		{
			switch (e.target)
			{
				case prevPageBtn: 
					picsStream.prevItem();
					break;
				case nextPageBtn: 
					picsStream.nextItem();
					break;
			}
		}
		
		override protected function handleSetRectangle(rec:Rectangle):void
		{
			super.handleSetRectangle(rec);
			horizantalLayout(rec.width, 10, [prevPageBtn], [nextPageBtn], picsListLayout);
		}
	}

}